<template>
  <div style="padding: 20px">
    <div class="title_font">
      用户财富值
    </div>
  </div>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="120px"
    >

      <el-form-item label="姓名：" prop="orderNo">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>

      <el-form-item label="手机号：" prop="orderNo">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>

      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 查询</el-button>
<!--        <el-button type="primary"  plain @click="openUserRateForm('用户返利值设置',1)"><Icon icon="ep:edit" class="mr-5px" />用户返利值设置</el-button>-->
<!--        <el-button type="success"  plain @click="openRateForm('推荐人返利值设置',2)"><Icon icon="ep:edit" class="mr-5px" />推荐人返利值设置</el-button>-->
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" border >
      <el-table-column label="姓名" align="center" prop="name" width="200px" />
      <el-table-column label="手机号" align="center" prop="mobile" width="200px" />
      <el-table-column label="财富值" align="center" prop="wealthValue" width="200px" />
      <el-table-column label="操作" align="center" width="300px">
        <template #default="scope" >


          <el-button type="primary"
                     size="small"
                     color="#296DFF"
                     @click="openWealthForm('扣除财富值-'+scope.row.name,scope.row.id)"
                     checkPermi="['hutai:wealth-record:update']"
          >
            扣除财富值
          </el-button>

          <el-button type="primary"
                     size="small"
                     color="#3C108F"
                     @click="openWealthRecordForm('财富历史纪录',scope.row.id)"
                     checkPermi="['hutai:wealth-record:query']"
          >
            财富历史纪录
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <RateForm ref="formRateRef" @success="getList" />
  <UserRateForm ref="formUserRateRef" @success="getList" />
  <WealthForm ref="formWealthRef" @success="getList" />
  <WealthRecordForm ref="formWealthRecordRef" @success="getList" />

</template>

<script setup lang="ts">
import * as WealthApi from '@/api/hutai/wealth'
import RateForm from "@/views/hutai/wealth/RateForm.vue";
import UserRateForm from "@/views/hutai/wealth/UserRateForm.vue";
import WealthForm from "@/views/hutai/wealth/WealthForm.vue";
import WealthRecordForm from "@/views/hutai/wealth/WealthRecordForm.vue";
defineOptions({ name: 'WealthIndex' })


const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: '',
  mobile: ''
})
const queryFormRef = ref() // 搜索的表单

const formRateRef = ref()
const formUserRateRef = ref()
const formWealthRef = ref()
const formWealthRecordRef = ref()


const openUserRateForm = (type: string, id?: number) => {
  formUserRateRef.value.open(type, id)
}

const openRateForm = (type: string, id?: number) => {
  formRateRef.value.open(type, id)
}

const openWealthForm = (type: string, id?: number) => {
  formWealthRef.value.open(type, id)
}

const openWealthRecordForm = (type: string, id?: number) => {
  formWealthRecordRef.value.open(type, id)
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await WealthApi.getWealthRecordPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}


/** 初始化 **/
onMounted(() => {
  getList()
})

</script>

<style lang="scss">

</style>
